<template>
	<view class="w-100">
		<scroll-view scroll-y class="w-100" :style="'height:' + windowHeight + 'px;'" @scrolltolower="scrolltolower">
			<view class="flex-1 row-ac" v-for="(item,index) in integralList" :key="index" @click="toIntegralDetail(item.id)">
				<view class="ml-2">
					<image v-if="item.types == 0" class="img-box"
						src="https://test.createbei.com/files/common/extractgoldcoins.png" mode="" />
					<image v-if="item.types == 1" class="img-box"
						src="https://test.createbei.com/files/common/draw-money.png" mode="" />
				</view>
				<view class="border-bottom flex-1 ml-3 font-s-4 py-3 row-ac">
					<view class="flex-1">
						<view class="font-s-5 in1line" v-if="item.types == 0">{{ item.points_way | wayFilter }}</view>
						<view class="font-s-5 in1line" v-if="item.types == 1">提现</view>
						<view class="text-light-muted font-s-2 mt-1">{{ item.created_time }}</view>
					</view>
					<view class="mr-2 font-w" :class="item.types == 0 ? 'text-main-color' : 'text-dark'">
						<text>{{ item.types == 0 ? '+' : '-' }}</text>{{ item.points_num }}
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		nowFormatTime
	} from '@/utils/time.js';
	import {
		integralListUrl
	} from "@/api/index"
	export default {
		data() {
			return {
				windowHeight:'',
				queryInfo: {
					page: 1,
					page_size: 12
				},
				integralList: [],
				integralTotal: 0
			}
		},
		filters: {
			wayFilter(way) {
				if (way === 0) {
					return '看广告获得贝币'
				} else if (way === 1) {
					return '发布文章获得贝币'
				} else if (way === 2) {
					return '点赞文章获得贝币'
				} else if (way === 3) {
					return '收藏文章获得贝币'
				}else if (way === 8) {
					return '做任务获得贝币'
				}
			},
		},
		onLoad() {
			this.getIntegralList()
		},
		created() {
			this.$getScreenInfo().then(res => {
				this.windowHeight = res.windowHeight
			})
		},
		methods: {
			getIntegralList() {
				this.$R.get(integralListUrl, this.queryInfo).then(res => {
					this.integralList = res.data.list
					this.integralTotal = res.data.total
				})
			},
			scrolltolower(){
				if (this.integralTotal > this.integralList.length) {
				  this.queryInfo.page_size += 12
				  this.getIntegralList();
				}
			},
			toIntegralDetail(integralId){
				uni.navigateTo({
					url: '/pages/user/data/integral-detail?integralId=' +　integralId
				});
			}
		}
	}
</script>

<style lang="scss">
	.screen-box {
		height: 82px;
		border-radius: 5rpx;
	}

	.img-box {
		width: 98rpx;
		height: 98rpx;
		border-radius: 50%;
	}
</style>